//
//  YHMachineManagementViewController.m
//  YHApp
//
//  Created by -- on 2021/6/25.
//

#import "HAMachineVC.h"
#import "HAMachineSubVC.h"
#import "SGPagingView.h"

@interface HAMachineVC ()<SGPageTitleViewDelegate,SGPageContentViewDelegate>

@property (nonatomic, strong) SGPageTitleView *pageTitleView;

@property (nonatomic, strong) SGPageContentView *pageContentView;


@end

@implementation HAMachineVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.baseTLabel.text = @"机具管理";
    
    if ([HASingle single].canalItemArray.count > 0) {
        [self getsubVC];
    }else {
        [HAHelper productChannelComplete:^(NSArray * _Nonnull array) {
            if (array > 0) {
                [self getsubVC];
            }
        }];
    }

    // Do any additional setup after loading the view.
}

-(void)getsubVC {
    NSMutableArray *titArr = [NSMutableArray array];
    NSMutableArray *vcArr = [NSMutableArray array];
    
    for (int i = 0; i < [HASingle single].canalItemArray.count; i ++) {
        HACanalItemMo *model = [HASingle single].canalItemArray[i];
        [titArr addObject:model.text];
        HAMachineSubVC *vc = [[HAMachineSubVC alloc]init];
        vc.canalItemModel = model;
        [vcArr addObject:vc];
    }
    

    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, app_topH+44, kUIScreen_w, 44) delegate:self titleNames:titArr titleFont:[UIFont systemFontOfSize:18]];
    [self.view addSubview:self.pageTitleView];
    self.pageTitleView.isTitleGradientEffect = NO;
    self.pageTitleView.indicatorLengthStyle = SGIndicatorLengthStyleEqual;
    self.pageTitleView.isNeedBounces = NO;
    self.pageTitleView.titleColorStateNormal = [UIColor colorWithHexString:@"#666F83"];
    self.pageTitleView.titleColorStateSelected = [UIColor colorWithHexString:@"#21252A"];
    self.pageTitleView.indicatorColor = [UIColor colorWithHexString:@"#000000"];
    self.pageTitleView.indicatorHeight = 1;
    self.pageTitleView.titleTextScaling = 0;
    self.pageTitleView.isOpenTitleTextZoom = YES;

    CGFloat contentViewHeight = kUIScreen_h-app_topH-64-app_bottomH-44-5;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, app_topH+44+44+5, kUIScreen_w, contentViewHeight) parentVC:self childVCs:vcArr];
    self.pageContentView.isScrollEnabled = YES;
    self.pageContentView.delegatePageContentView = self;
    [self.view addSubview:_pageContentView];

    [self.pageContentView setPageCententViewCurrentIndex:0];
    self.pageTitleView.selectedIndex = 0;

}


- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    self.pageTitleView.resetSelectedIndex = targetIndex;
}



@end
